﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<SearchCramModel>" %>
<%@ Import Namespace="eCRAM.Model" %>
<%@ Import Namespace="eCRAM.WebSite.Models" %>
<%@ Import Namespace="eCRAM.WebSite.Tools" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	eCram - Recherche d'un Cram
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <h2>Recherche d'un Cram</h2>

    
    <% using(Html.BeginForm("Search", "Search"))
       {
           %>
           
           <fieldset>
                <legend>Filtres</legend>

                <%= Html.LabelFor(model => model.Criterias.Month) %> <%= Html.DropDownListFor(model => model.Criterias.Month, ViewData.GetMonthList().AddEmptyListItem())%>
                <%= Html.LabelFor(model => model.Criterias.Year)%> <%= Html.DropDownListFor(model => model.Criterias.Year, ViewData.GetYearList().AddEmptyListItem())%>
                <%= Html.LabelFor(model => model.Criterias.Status)%> <%= Html.DropDownListFor(model => model.Criterias.Status, ViewData.GetCramStatusList().AddEmptyListItem())%>
                <%= Html.LabelFor(model => model.Criterias.UserId)%> <%= Html.ReadOnlyDropDownListFor(model => model.Criterias.UserId, ViewData.GetUsersList().AddEmptyListItem(),
                                SessionTools.User.Role == (int)UserRole.Engineer || SessionTools.User.Role == (int)UserRole.SubContractor)%>
                <%= Html.LabelFor(model => model.Criterias.ActivityId)%> <%= Html.DropDownListFor(model => model.Criterias.ActivityId, ViewData.GetRestrictedActivityList(SessionTools.User.Id).AddEmptyListItem())%>

                <input type="submit" value="Rechercher" />
           </fieldset>
    <% }

        if (Model.Results != null)
        {
            using (Html.BeginForm("Search", "Search", FormMethod.Post, new { id = "formResults" }))
            {
           %>
           
           <fieldset>
           <legend> Résultats </legend>

           <%
                var tableDescription = new TableDescription<SearchCramResultModel>();
                tableDescription.HiddenFieldName = "idCram";
                tableDescription.GetKeyMethod = item => item.Id;
                tableDescription.EditActionName = "EditCram";
                tableDescription.AddRow(new TableRowDescription<SearchCramResultModel>("Date", item => item.Date));
                tableDescription.AddRow(new TableRowDescription<SearchCramResultModel>("Utilisateur", item => item.UserName));
                tableDescription.AddRow(new TableRowDescription<SearchCramResultModel>("Statut", item => item.Status));
                tableDescription.AddRow(new TableRowDescription<SearchCramResultModel>("Projets", item => item.Projets));
                tableDescription.AddRow(new TableRowDescription<SearchCramResultModel>("Jours travaillés", item => item.NbWorkedDays));
                tableDescription.AddRow(new TableRowDescription<SearchCramResultModel>("Jours chômés", item => item.NbHolidays));

                if(Model.Results.Any())
                {
                    Response.Write(Html.TableForItems(model => model.Results, tableDescription, Model.Results, "formResults"));
                }
                else
                {
                    Response.Write("Aucun résultat ne correspond aux critères de recherche.");
                }
%>
           </fieldset>

           <%
        }
   } %>

</asp:Content>
